home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / hotspots / loadme.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  12.6 KB  |  352 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. --*******************************************************************************
  3. --*          Demo for:    HotSpots
  4. --*    Required files: reqFiles/animate.sx
  5. --*                    reqFiles/button.sx
  6. --*                    reqFiles/rollover.sx
  7. --*                    butnshp.sx
  8. --*                    rlovrshp.sx
  9. --*                    rlovrbut.sx
  10. --*                    NM8rlovr.sx
  11. --*                    NM8butn.sx
  12. --*            Author:    Su Quek - Kaleida Labs, Inc.
  13. --*-----------------------------------------------------------------------------*
  14. --*       Description: This script demonstrates how to create different types
  15. --*                    of hot spots.
  16. --*                    When you run "hotspots.sxt", you should see a window
  17. --*                    with 5 types of hotspots (penguins): 
  18. --*                        animated button
  19. --*                        animated rollover
  20. --*                        rollover button
  21. --*                        rollover shape
  22. --*                        button
  23. --*                    Move the mouse over each penguin and click on the buttons.
  24. --*                    Note: Clicking on the buttons does not really do anything
  25. --*                    except hilight the penguin in red.  If "hotspots.sxt" is
  26. --*                    run in the ScriptX authoring environment, "activate" or
  27. --*                    "multiactivate" is displayed in the Listener window.
  28. --*******************************************************************************
  29.  
  30. module DemoModule
  31.     uses ScriptX
  32. end
  33.  
  34. in module DemoModule
  35.  
  36. --*=============================================================================*
  37. --* Set up DirReps
  38. --*=============================================================================*
  39. global demoDir := theScriptDir
  40. global mediaDir := spawn theScriptDir "media"
  41. global reqFilesDir := spawn theScriptDir "reqfiles"
  42.  
  43. --*=============================================================================*
  44. --* Load required files
  45. --*=============================================================================*
  46. -- Load Animation
  47. fileIn reqFilesDir name:"animate.sx"
  48.  
  49. -- Load Button
  50. fileIn reqFilesDir name:"button.sx"
  51.  
  52. -- Load Rollover
  53. fileIn reqFilesDir name:"rollover.sx"
  54.  
  55. -- Load ButtonShape
  56. fileIn demoDir name:"butnshp.sx"
  57.  
  58. -- Load RolloverShape
  59. fileIn demoDir name:"rlovrshp.sx"
  60.  
  61. -- Load RolloverButton
  62. fileIn demoDir name:"rlovrbut.sx"
  63.  
  64. -- Load RolloverAnimation
  65. fileIn demoDir name:"nm8rlovr.sx"
  66.  
  67. -- Load AnimatedButton
  68. fileIn demoDir name:"nm8butn.sx"
  69.  
  70.  
  71. --*=============================================================================*
  72. --*    Define Demo 
  73. --*=============================================================================*
  74. class Demo (Window)
  75. end
  76.  
  77. method makeLabel self {class Demo} bbox label ->
  78. (
  79.     --*=========================================================================*
  80.     --* Create label
  81.     --*=========================================================================*
  82.     local txt := new TextPresenter boundary:bbox target:label
  83.     setDefaultAttr txt @brush whiteBrush
  84.     setDefaultAttr txt @alignment @center
  85.     
  86.     --*=========================================================================*
  87.     --* Add label to the demo window
  88.     --*=========================================================================*
  89.     prepend self txt
  90.     
  91.     return label
  92. )
  93.  
  94. --*=============================================================================*
  95. --*       Method name:    importBitmap
  96. --*             Class:    Demo
  97. --*             Usage: importBitmap self mediaDir bitmapFile
  98. --*                        mediaDir    - DirRep
  99. --*                        bitmapFile  - String object
  100. --*-----------------------------------------------------------------------------*
  101. --*       Description: Imports the given bitmap from the given directory.
  102. --*=============================================================================*
  103. method importBitmap self {class Demo} mediaDir bitmapFile ->
  104. (
  105.     local theStream := getStream mediaDir bitmapFile @readable
  106.     local theColormap := importMedia theImportExportEngine theStream @image @dib @colormap
  107.     local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap \
  108.                     colormap:theColormap container:self.title
  109.     theBMP.invisibleColor := (new RGBColor red:51 green:51 blue:255)
  110.     return theBMP
  111. )
  112.  
  113. --*=============================================================================*
  114. --*       Method name:    importSeries
  115. --*             Class:    Demo
  116. --*             Usage: importSeries self mediaDir
  117. --*                        mediaDir    - DirRep
  118. --*-----------------------------------------------------------------------------*
  119. --*       Description: Imports all bitmaps in the given directory.
  120. --*=============================================================================*
  121. method importSeries self {class Demo} mediaDir ->
  122. (
  123.     local series := #()
  124.     
  125.     --*=========================================================================*
  126.     --* Import all files in the 'media' folder
  127.     --*=========================================================================*
  128.     for bitmapFile in (getContents mediaDir) do
  129.          append series (importBitmap self mediaDir bitmapFile)
  130.  
  131.     --*=========================================================================*
  132.     --* Complete the animation loop
  133.     --*=========================================================================*
  134.     for i := ((size series) - 1) to 2 by -1 do
  135.         append series series[i]
  136.         
  137.     return series
  138. )
  139.  
  140.  
  141. method makeButtonShape self {class Demo} x y bmp1 bmp2 ->
  142. (
  143.     --*=========================================================================*
  144.     --* Create the hotspot
  145.     --*=========================================================================*
  146.     object butnShape (ButtonShape)
  147.         releasedBitmap      : bmp1
  148.         pressedBitmap      : bmp2 
  149.         settings
  150.             x              : x
  151.             y              : y
  152.             activateAction: (authordata self -> print "activate")
  153.             multiactivateAction: (authordata self n -> print "multiactivate")
  154.     end
  155.                             
  156.     --*=========================================================================*
  157.     --* Add hotspot to the demo window
  158.     --*=========================================================================*
  159.     prepend self butnShape
  160. )
  161.  
  162. method makeRolloverShape self {class Demo} x y bmp1 bmp2 ->
  163. (
  164.     --*=========================================================================*
  165.     --* Create the hotspot
  166.     --*=========================================================================*
  167.     object rlovrShape (RolloverShape)
  168.         enterBitmap            : bmp1
  169.         exitBitmap            : bmp2
  170.         settings
  171.             x              : x
  172.             y              : y
  173.     end
  174.                             
  175.     --*=========================================================================*
  176.     --* Add hotspot to the demo window
  177.     --*=========================================================================*
  178.     prepend self rlovrShape
  179. )
  180.  
  181.  
  182. method makeRolloverButton self {class Demo} x y bmp1 bmp2 bmp3 ->
  183. (
  184.     --*=========================================================================*
  185.     --* Create the hotspot
  186.     --*=========================================================================*
  187.     object rlovrButton (RolloverButton)
  188.         enterBitmap            : bmp1
  189.         exitBitmap            : bmp2             -- NOTE:exitBitmap = releasedBitmap
  190.         releasedBitmap      : bmp2            
  191.         pressedBitmap      : bmp3 
  192.         settings
  193.             x              : x
  194.             y              : y
  195.             activateAction: (authordata self -> print "activate")
  196.             multiactivateAction: (authordata self n -> print "multiactivate")
  197.     end
  198.                             
  199.     --*=========================================================================*
  200.     --* Add hotspot to the demo window
  201.     --*=========================================================================*
  202.     prepend self rlovrButton
  203. )
  204.     
  205. method makeAnimatedRollover self {class Demo} x y series ->
  206. (
  207.     --*=========================================================================*
  208.     --* Create the hotspot
  209.     --*=========================================================================*
  210.     object NM8Rollover (RolloverAnimation)
  211.         series                : series
  212.         scale              : 8
  213.         settings
  214.             x              : x
  215.             y              : y
  216.     end
  217.                             
  218.     --*=========================================================================*
  219.     --* Add hotspot to the demo window
  220.     --*=========================================================================*
  221.     prepend self NM8Rollover
  222. )
  223.  
  224. method makeAnimatedButton self {class Demo} x y series bmp1 ->
  225. (
  226.     --*=========================================================================*
  227.     --* Create the hotspot
  228.     --*=========================================================================*
  229.     object NM8Button (AnimatedButton)
  230.         series                : series
  231.         scale              : 8
  232.         pressedBitmap       : bmp1
  233.         settings
  234.             x              : x
  235.             y              : y
  236.             activateAction: (authordata self -> print "activate")
  237.             multiactivateAction: (authordata self n -> print "multiactivate")
  238.     end
  239.                             
  240.     --*=========================================================================*
  241.     --* Add hotspot to the demo window
  242.     --*=========================================================================*
  243.     prepend self NM8Button
  244. )
  245.  
  246. --*=============================================================================*
  247. --*       Method name:    init
  248. --*             Class:    Demo
  249. --*             Usage: init self 
  250. --*-----------------------------------------------------------------------------*
  251. --*       Description: Creates a 400x200 window.
  252. --*=============================================================================*
  253. method init self {class Demo} #rest args ->
  254. (
  255.     -- Create a 400x200 window 
  256.     apply nextMethod self boundary:(new rect x2:400 y2:200) \
  257.                           centered:true \
  258.                           fill:(new Brush color:(new RGBColor red:51 green:51 blue:255)) \
  259.                           name:"Hotspots" args
  260.     return self
  261. )
  262.  
  263. --*=============================================================================*
  264. --*       Method name:    afterInit
  265. --*             Class:    Demo
  266. --*             Usage: afterInit self 
  267. --*-----------------------------------------------------------------------------*
  268. --*       Description: Calls methods to create the different types of hotspots.
  269. --*=============================================================================*
  270. method afterInit self {class Demo} #rest args ->
  271. (                         
  272.     --*=========================================================================*
  273.     --* Create an actuator controller to control all the buttons in the demo
  274.     --*    window.
  275.     --*=========================================================================*
  276.     new ActuatorController space:self wholespace:true
  277.  
  278.     --*=========================================================================*
  279.     --* Import all required bitmaps
  280.     --*=========================================================================*
  281.     local pen3Dir := spawn mediaDir "pen3anim"
  282.     local pen3Series := importSeries self pen3Dir
  283.     
  284.     local pen4Dir := spawn mediaDir "pen4anim"
  285.     local pen4Series := importSeries self pen4Dir
  286.  
  287.     local pen1a := importBitmap self mediaDir "pen1a.bmp"
  288.     local pen1c := importBitmap self mediaDir "pen1c.bmp"
  289.     local pen2a := importBitmap self mediaDir "pen2a.bmp"
  290.     local pen2c := importBitmap self mediaDir "pen2c.bmp"
  291.     local pen3a := importBitmap self mediaDir "pen3a.bmp"
  292.     local pen3b := importBitmap self mediaDir "pen3b.bmp"
  293.     local pen3c := importBitmap self mediaDir "pen3c.bmp"
  294.     
  295.     --*=========================================================================*
  296.     --* Make hotspots
  297.     --*=========================================================================*
  298.     makeButtonShape self 305 87 pen1a pen1c
  299.     makeRolloverShape self 232 90 pen2a pen2c
  300.     makeRolloverButton self 154 71 pen3c pen3a pen3b
  301.     makeAnimatedRollover self 79 80 pen4Series
  302.     makeAnimatedButton self 0 71 pen3Series undefined
  303.     
  304.     --*=========================================================================*
  305.     --* Make labels for hotspots
  306.     --*=========================================================================*
  307.     makeLabel self (new rect x1:3 y1:20 x2:83 y2:70) "Animated Rollover Button"
  308.     makeLabel self (new rect x1:80 y1:25 x2:160 y2:60) "Animated Rollover"
  309.     makeLabel self (new rect x1:160 y1:25 x2:240 y2:60) "Rollover Button"
  310.     makeLabel self (new rect x1:240 y1:28 x2:320 y2:50) "Rollover"
  311.     makeLabel self (new rect x1:320 y1:28 x2:400 y2:50) "Button"
  312.  
  313.     --*=========================================================================*
  314.     --* Display the demo window
  315.     --*=========================================================================*
  316.     show self
  317.     
  318.     return self
  319. )
  320.  
  321. --*=============================================================================*
  322. --*    Create a title container
  323. --*=============================================================================*
  324. object tc (TitleContainer)
  325.     dir        : demoDir
  326.     path    : "hotspots.sxt" 
  327.     name    : "Hotspots"
  328. end        
  329.     
  330. --*=============================================================================*
  331. --*    Create demo
  332. --*=============================================================================*
  333. object win (Demo)
  334.     title:tc
  335. end
  336.  
  337. --*=============================================================================*
  338. --*    Undefine global DirReps
  339. --*=============================================================================*
  340. demoDir := undefined
  341. reqFilesDir := undefined
  342. mediaDir := undefined
  343.  
  344. --*=============================================================================*
  345. --*    Store module in the title container
  346. --*=============================================================================*
  347. append tc (getModule @DemoModule)
  348. tc.startUpAction := (tc ->    load tc[1]
  349.                             show win)
  350. close tc
  351. -->>>
  352.